package com.example.speeddating.mapper;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.speeddating.entity.TaohuaDetail;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author tina
 * @since 2023-06-28 11:14:34
 */
@Mapper
public interface TaohuaDetailMapper extends BaseMapper<TaohuaDetail> {

    @Select(value = "SELECT SUM(count) FROM taohua_detail WHERE user_id = #{userId}")
    public int selectTaohuaSum(Long userId);

    @Select(value = "SELECT YEAR(create_time) AS year, MONTH(create_time) AS month, COUNT(*) AS sum\n" +
            "FROM taohua_detail WHERE user_id = #{userId}\n" +
            "GROUP BY YEAR(create_time), MONTH(create_time)\n" +
            "ORDER BY YEAR(create_time) DESC, MONTH(create_time) DESC")
    Page<TaohuaDetail> getList(Page<TaohuaDetail> detailPage, long userId);

    @Select(value = "SELECT *,YEAR(create_time) AS year, MONTH(create_time) AS month FROM taohua_detail WHERE YEAR(create_time) = #{year} AND MONTH(create_time) = #{month} and user_id = #{userId} ORDER BY create_time DESC")
    public List<TaohuaDetail> getListByYearMonth(int year, int month, long userId);
}
